<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/pics/now/dirs">
<html>
<table>
<xsl:variable name="s">4</xsl:variable>
<xsl:for-each select="dir">
	<xsl:for-each select="image">
		<xsl:variable name="p"><xsl:value-of select="position()-1"/></xsl:variable>
		<xsl:if test="($p  mod $s)=0">
			<tr>
			<xsl:for-each select="../image[(position() &gt;= $p+1) and (position() &lt; ($p+1+$s))]">
				<td><xsl:call-template name="image"/></td>
			</xsl:for-each>
			</tr>
		</xsl:if>
	</xsl:for-each>
</xsl:for-each>
</table>
</html>
</xsl:template>

<xsl:template name="image" match="image">
<td>
<table border="1">
<tr><td align="center">
<a><xsl:attribute name="href"><xsl:value-of select="file/@path"/></xsl:attribute>
	<img>
	<xsl:attribute name="src">
		<xsl:value-of select="thumb/@path"/>
	</xsl:attribute>
	</img>
</a>
</td></tr>
<tr><td>
<a style="font-size:small"><xsl:attribute name="href"><xsl:value-of select="file/@path"/></xsl:attribute>
<xsl:value-of select="descr"/></a>
</td></tr>
</table>
</td>
</xsl:template>

</xsl:stylesheet>
